home *** CD-ROM | disk | FTP | other *** search
- // GETINFO SCRIPTING
- // http://cinema.ptgate.pt/(imagem grande)
- // Script feito pelo O Guardiπo versπo 1.0 Alpha 2
- // 29-05-2004
-
-
- (***************************************************
- * For use with Ant Movie Catalog 3.4.0 *
- * www.antp.be/software/moviecatalog *
- * *
- * The source code of the script can be used in *
- * another program only if full credits to *
- * script author and a link to Ant Movie Catalog *
- * website are given in the About box or in *
- * the documentation of the program *
- * *
- * Please dont remove credits *
- * Reportem os erros para bruno_mga@hotmail.com *
- ***************************************************)
- program PTGate;
- const
- BaseAddress = 'http://cinema.ptgate.pt/';
- ManualPictureSelect = True;
- ExternalPictures = False;
- DescriptionToImport = 2;
- var
- MovieName: string;
- MovieURL: string;
- function HTMLRemove(Value: String): String;
- begin
- HTMLDecode(Value);
- HTMLRemoveTags(Value);
- Value := Trim(Value);
- result := Value;
- end;
-
- procedure AnalyzeFilmPage(Address: String);
- var
- Page : TStringList;
- Line, Value : string;
- LineNr, BeginPos, EndPos: Integer;
- AllTitles: TStringList;
- url_imdb:string;
- begin
- Page := TStringList.Create;
- Address:='http://cinema.ptgate.pt/filme.php?code='+Address;
- Page.Text := GetPage(Address);
- SetField(fieldURL, Address);
-
-
-
- //obter nome do filme
- LineNr := FindLine('<td bgcolor=#6496D2 width=360 colspan=2><table border=0 cellspacing=0 cellpadding=0><td width=5><br></td><td><font color=white><b class=ttl>', Page, 0);
- if LineNr<>-1 then
- begin
- Value := Page.GetString(LineNr+1);
- BeginPos := pos('</b><br><', value)+9;
- value:=copy(value,4,BeginPos);
-
- AllTitles := TStringList.Create;
- AllTitles.Add(HTMLRemove(value));
-
- //por o the no principio do nome
- if pos(', The</b><br>',value) <>0 then
- begin
- url_imdb:=HTMLRemove(value);
- value:= StringReplace(value, ', The</b><br>', '');
- value:='The '+value;
- value:=HTMLRemove(value);
- AllTitles.Add(value);
- end;
-
- value:=HTMLRemove(value);
- SetField(fieldOriginalTitle, Value);
- end;
-
- //imagem
- Value := Page.GetString(LineNr-1);
- Value:= StringReplace(value, ' "></td>', '');
- Value:= StringReplace(value, ' ', '');
- Value:='http://cinema.ptgate.pt/'+value;
- GetPicture(Value, False);
-
- //obter nome traduzido
- Value := Page.GetString(LineNr+1);
- BeginPos := pos('><i class=subttl>', value)+17;
- EndPos:=Pos('<br></i></td><td width=5><br></',value);
- value:=copy(value,BeginPos,EndPos-BeginPos);
- value:=Copy(value,1,endpos);
- value:=HTMLRemove(value);
- SetField(fieldTranslatedTitle, Value);
-
-
- //Realizador
- LineNr := FindLine('<!-- real -->', Page, 0);
- if LineNr<>-1 then
- begin
- Value := Page.GetString(LineNr+3);
- BeginPos:=Pos('>',value)+1;
- EndPos:=Pos('</a>',value);
- value:=copy(value,BeginPos,EndPos-BeginPos);
- value:=HTMLRemove(value);
- SetField(fieldDirector, Value);
- end;
-
- //actores
- LineNr := FindLine('><b>IntΘrpretes: </b>', Page, 0);
- if LineNr<>-1 then
- begin
- Value := Page.GetString(LineNr+1);
- value:= StringReplace(value,' </font></td>' , '');
- value:= StringReplace(value,' ' , '');
- value:=HTMLRemove(value);
- SetField(fieldActors, Value);
- end;
-
- //ano
- LineNr := FindLine('<!-- ano -->', Page, 0);
- if LineNr<>-1 then
- begin
- Value := Page.GetString(LineNr+1);
- value:=HTMLRemove(value);
- BeginPos:=pos('Ano:',value);
- Value:=Copy(value,beginPos+6,length(value));
- SetField(fieldYear, value);
- end;
- url_imdb:=url_imdb+' ('+Value+')';
-
- //genero
- LineNr := FindLine('<!-- gene -->', Page, 0);
- if LineNr<>-1 then
- begin
- Value := Page.GetString(LineNr+1);
- BeginPos:=Pos('<font size=2 face=verdana,arial>',Value);
- EndPos:=Pos('</font></td>',Value);
- value:=Copy(value,BeginPos,EndPos-BeginPos);
- value:=HTMLRemove(value);
- SetField(fieldCategory, value);
- end;
-
- //paφs
- LineNr := FindLine('<!-- pais -->', Page, 0);
- if LineNr<>-1 then
- begin
- Value:= Page.GetString(LineNr+1);
- BeginPos:=Pos('<font size=2 face=verdana,arial>',Value);
- EndPos:=Pos('</font></td>',Value);
- value:=Copy(value,BeginPos,EndPos-BeginPos);
- value:=HTMLRemove(value);
- SetField(fieldCountry, value);
- end;
-
- //descriτπo
- LineNr := FindLine('<!-- wall -->', Page, 0);
- Value:= Page.GetString(LineNr+1);
- if (LineNr<>-1) and (pos('<b>Sinopse</b><br>',value)<>0) then
- begin
- Value:= Page.GetString(LineNr+2);
- EndPos:=Pos('<br><br></font>',value);
- Value:=Copy(Value,1,EndPos);
- Value:=HTMLRemove(value);
- SetField(fieldDescription, value);
- end;
-
- url_imdb:=AllTitles.GetString(0)+' '+url_imdb;
-
- //imdb
- url_imdb:= StringReplace(url_imdb, ' ', '+');
- url_imdb:='http://us.imdb.com/Title?'+url_imdb;
- Page.Text := GetPage(url_imdb);
-
- // Length
- LineNr := FindLine('Runtime:', Page, 0);
- if LineNr > -1 then
- begin
- Line := Page.GetString(LineNr + 1);
- EndPos := pos(' min', Line);
- if EndPos = 0 then
- EndPos := pos(' /', Line);
- if EndPos = 0 then
- EndPos := Length(Line);
- if Pos(':', Line) < EndPos then
- BeginPos := Pos(':', Line) + 1
- else
- BeginPos := 1;
- Value := copy(Line, BeginPos, EndPos - BeginPos);
- SetField(fieldLength, Value);
- end;
-
- // Rating
- LineNr := FindLine('User Rating:', Page, 0);
- if LineNr > -1 then
- begin
- Line := Page.GetString(LineNr + 4);
- if Pos('/10', Line) > 0 then
- begin
- BeginPos := pos('<b>', Line) + 3;
- Value := IntToStr(Round(StrToInt(StrGet(Line, BeginPos), 0) + (StrToInt(StrGet(Line, BeginPos + 2), 0) / 10)));
- SetField(fieldRating, Value);
- end;
- end;
-
-
- AllTitles.Add(Getfield(fieldOriginalTitle));
- GetMoviePicture('English', Page, AllTitles);
- AllTitles.Free;
-
- end;
-
- procedure GetMoviePicture(Language: string; Page, AllTitles: TStringList);//copiado do IMDB (large Pic)
- var
- Line, Value, Value2, Aka, PictureAddress: string;
- AmazonPage: TStringList;
- FoundOnAmazon, PickTreeSelected, PictureAvailable: Boolean;
- TitleRef, ImgRef, NoImage: string;
- LineNr, BeginPos, EndPos, PickTreeCount, ParagraphIndex, Index, TitleLine, LastMatch: Integer;
- begin
- FoundOnAmazon := False;
-
- // Find Alternate Titles for Movies which are not in English
- Aka := '';
- if Language <> 'English' Then
- begin
- LineNr:= FindLine('Also Known As',Page,0);
- EndPos:=0;
- if LineNr > -1 then
- begin
- Line := Page.GetString(LineNr);
- repeat
- Aka:=FindValue('<br>','<br>',Page,LineNr,Line);
- if Aka <> '' then
- begin
- BeginPos:=1;
- EndPos:=Pos('(',Line);
- if EndPos = 0 then
- EndPos := Length(Aka);
- Value := copy(Aka, BeginPos, EndPos - BeginPos - 1);
- Value:=TransFormIMDBTitle(Value);
- AllTitles.Add(Value);
- end;
- until (Pos('Runtime',Line) > 0) or (Pos('MPAA',Line) > 0 ) or (Pos('Country', Line) > 0) or (Pos('Certification', Line) > 0);
- end;
- end;
-
- TitleRef:='dvd>';
- ImgRef:='dvd><img';
- NoImage:='/icons/dvd-no-image.gif';
- LineNr := FindLine('title="DVD available at Amazon.com"', Page, 0);
- if LineNr = -1 then
- begin
- LineNr := FindLine('title="VHS available at Amazon.com"', Page, 0);
- if LineNr > -1 then
- begin
- TitleRef:='video>';
- ImgRef:='video><img';
- NoImage:='/icons/video-no-image.gif';
- end;
- end;
-
- if LineNr > -1 then
- begin
- Line := Page.GetString(LineNr);
- if(TitleRef='dvd>') then
- begin
- EndPos := pos('title="DVD', Line);
- BeginPos := pos('title="VHS', Line);
- while (BeginPos > 0) and (BeginPos<EndPos) do
- begin
- Delete(Line, 1, BeginPos+1);
- BeginPos := pos('title="VHS', Line);
- end;
- end;
- BeginPos := Pos('href="', Line) + 5;
- Delete(Line, 1, BeginPos);
- EndPos := Pos('"', Line);
- Value := Copy(Line, 1, EndPos - 1);
- AmazonPage := TStringList.Create;
- AmazonPage.Text := GetPage('http://us.imdb.com' + Value);
-
- // Original Title
- Value2 := AllTitles.GetString(0);
- // Value2 := TransFormIMDBTitle(Value2);
-
- PickTreeClear;
- PickTreeCount := 0;
- PickTreeAdd('Available Titles for matching a picture to: ' + Value2, '');
-
- ParagraphIndex := 1;
- LineNr := 0;
- LastMatch := -1;
- TitleLine := -1;
- repeat
- LineNr := FindLine('<b>'+IntToStr(ParagraphIndex)+'.', AmazonPage, LineNr);
-
- if LineNr > -1 then
- begin
- TitleLine:=LineNr;
- Value:='';
- PictureAvailable:=False;
- repeat
- TitleLine:=TitleLine +1;
- Line:= AmazonPage.GetString(TitleLine);
- BeginPos:=0;
- if Pos(TitleRef,Line) > 0 then
- begin
- if Pos(ImgRef,Line) = 0 then
- begin
- for Index:=0 to AllTitles.Count -1 do
- begin
- Value2:=AllTitles.GetString(Index);
- BeginPos:=Pos(Value2,Line);
- if BeginPos > 0 then
- Break;
- end;
- // Match not found
- if BeginPos = 0 then
- begin
- BeginPos:=Pos(TitleRef,Line)+Length(TitleRef);
- EndPos:=Pos('</a>',Line);
- Value:=Copy(Line,BeginPos,EndPos-BeginPos);
- end;
- end
- else
- begin
- PictureAvailable:=(Pos(NoImage,Line) = 0);
- PictureAddress:=IntToStr(TitleLine);
- end;
- end;
- if BeginPos > 0 then
- Break;
- until (Pos('</table>',Line ) > 0);
-
- // Try to Find a Title Match
- if Pos(Value2,Line) > 0 then
- begin
- // Compare Current Title to Original
- BeginPos := Pos(TitleRef, Line) + Length(TitleRef) -1;
- Delete(Line, 1, BeginPos);
- EndPos:= Pos('(',Line);
- if EndPos = 0 Then
- EndPos := Pos('</a>', Line);
- Value := Copy(Line, 1, EndPos - 1);
- Value:= Trim(Value);
- if Value = Value2 then
- begin
- if PictureAvailable then
- LastMatch:=LineNr;
- //Break
- end;
- end;
- if PictureAvailable then
- begin
- PickTreeAdd(Value,PictureAddress);
- PickTreeCount:=PickTreeCount+1;
- end;
- end;
- ParagraphIndex:=ParagraphIndex+1;
- until (LineNr = -1);
- LineNr:=LastMatch;
- if (LineNr = -1) then
- begin
- // Handle Amazon Page Redirection(s)
- LineNr:= FindLine('You clicked on this item',AmazonPage,0);
- if (LineNr = -1) then
- LineNr:=FindLine('Customers who bought',AmazonPage,0);
- // Display the Picture Selection Window
- if (LineNr = -1) and ManualPictureSelect and (PickTreeCount > 0) then
- begin
- PickTreeSelected:=PickTreeExec(PictureAddress);
- if PickTreeSelected then
- LineNr:=StrToInt(PictureAddress,0);
- end;
- if (LineNr > -1 ) then
- begin
- LineNr := FindLine('src="http://images.amazon.com/images/P/',AmazonPage, LineNr);
- if not PickTreeSelected then
- TitleLine:= FindLine('/exec/obidos/ASIN/',AmazonPage, 0);
- if (LineNr > TitleLine) then
- LineNr:=-1;
- if LineNr > -1 then
- begin
- Line := AmazonPage.GetString(LineNr);
- BeginPos := Pos('src="http://images.amazon.com/images/P/', Line) + 4;
- Delete(Line, 1, BeginPos);
- EndPos := Pos('"', Line);
- Value := Copy(Line, 1, EndPos - 1);
- Value := StringReplace(Value, 'TZZZZZZZ', 'LZZZZZZZ');
- Value := StringReplace(Value, 'THUMBZZZ', 'LZZZZZZZ');
- GetPicture(Value, ExternalPictures);
- FoundOnAmazon := True;
- end;
- end;
- end
- else
- begin
- LineNr := FindLine('http://images.amazon.com/images/P/', AmazonPage, LineNr);
- if LineNr < TitleLine then
- begin
- Line := AmazonPage.GetString(LineNr);
- BeginPos := Pos('src="', Line) + 4;
- Delete(Line, 1, BeginPos);
- EndPos := Pos('"', Line);
- Value := Copy(Line, 1, EndPos - 1);
- Value := StringReplace(Value, 'THUMBZZZ', 'LZZZZZZZ');
- GetPicture(Value, ExternalPictures);
- FoundOnAmazon := True;
- end;
- end;
- AmazonPage.Free;
- end;
-
- if not FoundOnAmazon then
- begin
- { not found on Amazon, so taking what's available directly on IMDB.
- if we are lucky, a picture from amazon but directly linked in the page }
- LineNr := FindLine('<img border="0" alt="cover"', Page, 0);
- if LineNr > -1 then
- begin
- Line := Page.GetString(LineNr);
- BeginPos := pos('src="', Line) + 4;
- Delete(Line, 1, BeginPos);
- EndPos := pos('"', Line);
- Value := copy(Line, 1, EndPos - 1);
- GetPicture(Value, ExternalPictures);
- end;
- end;
- end;
-
-
-
-
- function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
- var
- i: Integer;
- begin
- result := -1;
- if StartAt < 0 then
- StartAt := 0;
- for i := StartAt to List.Count-1 do
- if Pos(Pattern, List.GetString(i)) <> 0 then
- begin
- result := i;
- Break;
- end;
- end;
-
- procedure AnalyzePage(Address: string);
- var
- Page: TStringList;
- LineNr, StartPos, EndPos: Integer;
- Line: string;
- x:integer;
- MovieAddress, findMovieName,linedown : string;
- guardar,url, nome_filme:string;
- begin
- PickTreeClear;
- Page := TStringList.Create;
- Page.Text := GetPage(Address);
-
- if (pos('Nπo foram encontrados filmes ou pessoas que satisfaτam a sua pesquisa.', Page.Text)<>-1) then //se existe
- begin
- LineNr := FindLine('filme.php?code=', Page, LineNr);
- Line := Page.GetString(LineNr);
- repeat
- StartPos := pos('filme.php?code=', Line)+15;
- if StartPos=15 then break;
-
- guardar:=Copy(line,StartPos+1,9999);
- line:=Copy(line,StartPos,9999);
- StartPos := pos('>',line)+1;
- url:=(copy(line,1,StartPos-3));
- EndPos := pos('</a>',line)-1;
- line := copy(Line, StartPos, EndPos - StartPos+1);
- nome_filme:=line;
- PickTreeAdd(nome_filme, url);
- line:=guardar;
-
- until (nome_filme='');
-
- if PickTreeExec(Address) then begin
- AnalyzeFilmPage(Address);
- end;
- Page.Free;
- end;
- DisplayResults;
- end;
- begin
- PickListClear;
- MovieName := GetField(fieldOriginalTitle);
- if Input('Importar do cinema.ptgate.pt', 'Escreva o nome do filme:', MovieName) then begin
- //espaτo nπo sπo permitidos
- MovieName := StringReplace(MovieName, ' ', '%20');
- AnalyzePage('http://cinema.ptgate.pt/pesquisa.php?tx='+MovieName);
- end;
- end.
-
-